



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import JCP.Browser;
import JCP.JavaClientPage;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JSlider;
import javax.swing.JTextField;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author Pham
 */
public class ContacUs extends JPanel implements JavaClientPage {

    protected Browser br;
    protected Map<String, Object> parameters;
    public Map<String, String> setItem = new HashMap<String, String>();
    JTextField field;
    JButton button;
    JSlider slider;
    JLabel labelpictcure;
    ActionListener updateProBar;
    Timer timer;
    JProgressBar progressBar;
    JButton button2;
    ArrayList<JMenu> menuList;

    /**
     *
     */
    public ContacUs() {
    }
    public JPanel JavaClientPage = new JPanel();

    @Override
    public JPanel getBody() {
        setItem.put("name", "Chin Yi");
        //setItem.put("Link", "Kend");
        br.localstorage(setItem);
        JLabel locallb = new JLabel("Value is: " + br.localstorage("name"));
        JavaClientPage.add(locallb);

        JavaClientPage.setLayout(new BoxLayout(JavaClientPage, BoxLayout.Y_AXIS));
        JavaClientPage.setPreferredSize(new Dimension(1000, 600));
        JavaClientPage.setMaximumSize(JavaClientPage.getPreferredSize());
        JavaClientPage.setMinimumSize(JavaClientPage.getPreferredSize());
        // JMenuBar menuBar = new JMenuBar();
        // menuBar.setBackground(Color.pink);
        //menuBar.setPreferredSize(new Dimension(240, 40));
        //  menuBar.setMaximumSize( menuBar.getPreferredSize()); 
        // menuBar.setMinimumSize( menuBar.getPreferredSize()); 
        // menuBar.setAlignmentX(Component.CENTER_ALIGNMENT);
        JMenu home = new JMenu("Open");
        JMenu contactus = new JMenu("Save");
        JMenu bioraphy = new JMenu("Delete");
        JMenu gallery = new JMenu("Haha");
        menuList = new ArrayList<>();
        menuList.add(home);
        menuList.add(contactus);
        menuList.add(bioraphy);
        menuList.add(gallery);
        br.setMenu(menuList);


        home.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                br.go("http://localhost/Home");
            }
        });

        contactus.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                br.go("http://localhost/ContacUs");
            }
        });




        // JavaClientPage.add(menuBar);
        slider = new JSlider(0, 150, 0);
        slider.setPreferredSize(new Dimension(150, 30));
        slider.setMaximumSize(slider.getPreferredSize());
        slider.setMinimumSize(slider.getPreferredSize());

        JavaClientPage.add(slider);

        slider.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent event) {
                int value = slider.getValue();
                if (value == 0) {
                    labelpictcure.setIcon(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/1.jpg")).getImage()
                            .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));
                    // label.setText("1");
                } else if (value > 0 && value <= 30) {
                    labelpictcure.setIcon(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/2.jpg")).getImage()
                            .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));

                } else if (value > 30 && value < 80) {
                    labelpictcure.setIcon(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/3.jpg")).getImage()
                            .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));

                } else if (value > 80 && value < 120) {
                    labelpictcure.setIcon(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/4.jpg")).getImage()
                            .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));

                } else {
                    labelpictcure.setIcon(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/5.jpg")).getImage()
                            .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));

                }
            }
        });


        labelpictcure = new JLabel(new ImageIcon(((new ImageIcon(this.getClass().getResource("/images/1.jpg")).getImage()
                .getScaledInstance(690, 460, java.awt.Image.SCALE_DEFAULT)))));
        JavaClientPage.add(labelpictcure);

        progressBar = new JProgressBar();

        progressBar.setMaximumSize(new Dimension(150, 20));
        progressBar.setMinimumSize(new Dimension(150, 20));
        progressBar.setPreferredSize(new Dimension(150, 20));

        progressBar.setAlignmentX(0f);

        JavaClientPage.add(progressBar);
        JavaClientPage.add(Box.createRigidArea(new Dimension(0, 20)));

        button2 = new JButton("Start");
        button2.setFocusable(false);
        button2.setMaximumSize(button2.getPreferredSize());

        updateProBar = new ActionListener() {
            public void actionPerformed(ActionEvent actionEvent) {
                int val = progressBar.getValue();
                if (val >= 100) {
                    timer.stop();
                    button2.setText("End");
                    return;
                }

                progressBar.setValue(++val);
            }
        };

        timer = new Timer(50, updateProBar);

        button2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (timer.isRunning()) {
                    timer.stop();
                    button2.setText("Start");

                } else if (button2.getText() != "End") {
                    timer.start();
                    button2.setText("Stop");
                }

            }
        });
        JavaClientPage.add(button2);












        return JavaClientPage;

    }

    @Override
    public void setBrowser(Browser br) {
        this.br = br;
    }

    @Override
    public void setParameters(Map<String, Object> parameters) {
        this.parameters = parameters;
    }
}
